#include "StdAfx.h"
#include "PlayerFactory.h"
#include "Player.h"
#include "PlayerPack.h"
#include "Road.h"
#include "House.h"
#include "Board.h"
#include "BoardItems.h"

namespace catan
{
	PlayerFactory::PlayerFactory(void)
	{
	}
	
	PlayerFactory::~PlayerFactory(void)
	{
	}

	Handle<Player> PlayerFactory::CreatePlayer( PlayerColor::Enum color, Handle<Board> board)
	{
		mPlayer = board->mBoardItems->ToHandle(new Player());
		mPlayer->mColor = color;
		mPlayer->mPlayerPack = CreatePlayerPack(board);
		return mPlayer;
	}

	Handle<PlayerPack> PlayerFactory::CreatePlayerPack(Handle<Board> board)
	{
		Handle<PlayerPack> pack = board->mBoardItems->ToHandle(new PlayerPack());
		for (int i = 0; i < 15; ++i)
		{
			pack->mRoads.Add(board->mBoardItems->ToHandle(new Road()));
		}

		for (int i = 0; i < 5; ++i)
		{
			pack->mHouses.Add(board->mBoardItems->ToHandle(new House()));
		}

		for (int i = 0; i < 4; ++i)
		{
			pack->mSettlements.Add(board->mBoardItems->ToHandle(new Settlement()));
		}
		pack->SetPlayerColor(mPlayer->mColor);
		return pack;
	}

// 	void PlayerFactory::RecyclePlayer( Handle<Player> player )
// 	{
// 		player->mPlayerPack->mRoads.DeleteAll();
// 		player->mPlayerPack->mHouses.DeleteAll();
// 		player->mPlayerPack->mSettlements.DeleteAll();
// 
// 		Recycle(player->mPlayerPack);
// 		Recycle(player);
// 
// 	}
}	


